<?xml version="1.0" encoding="UTF-8" ?> 
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" 
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="${m.packageName}.${m.className}">

	<resultMap type="${m.resMapClsName}" id="${m.resBeaName}ResultMap">
		${m.resMapStr}
	</resultMap>
	<sql id="Base_Column_List" >
      ${m.listColsStr}
    </sql>

    <insert id="add" parameterType="${m.resMapClsName}">
	    INSERT INTO ${m.tableName}
	      (${m.insertColsStr})
	    VALUES
	      (${m.insertColsVal})
	    <selectKey keyProperty="${m.idPro}" order="AFTER" resultType="long">
             SELECT last_insert_id() as ${m.idCol}
        </selectKey>  
	</insert>
	
	<update id="del" parameterType="${m.mclssFullName}">
		UPDATE ${m.tableName} SET del_flag='1' 
		where 1=1
			${m.delWhereStr}
	</update>
	
	<delete id="dels" parameterType="String">
		UPDATE ${m.tableName} SET del_flag='1' 
		<where>
			<if test="ids != null">
				${m.idCol} in (${m.escape}{ids})
			</if>
		</where>
	</delete>
	
	<update id="edit" parameterType="${m.resMapClsName}">
		update ${m.tableName}
		<set>
			${m.editSetStr}
		</set>
		where del_flag='0' and ${m.idCol} = ${m.escape}{${m.idPro}}
	</update>
	
	<update id="edits">
		update ${m.tableName}
		<set>
			${m.editsSetStr}
		</set>
		where del_flag='0' and ${m.idCol} in (${m.dscape}{ids})
	</update>
	
	<select id="count" resultType="int" parameterType="${m.mclssFullName}">
		SELECT count(*) from ${m.tableName}
		where del_flag='0'
			${m.countWhereStr}
	</select>
	
	<select id="list" resultMap="${m.resBeaName}ResultMap">
		SELECT 
        <include refid="Base_Column_List" />
        FROM
        	${m.tableName} t
        WHERE t.del_flag='0'
			${m.listWhereStr}
			LIMIT ${m.escape}{beginNum},${m.escape}{endNum}
	</select>
	
	<select id="selectListByDto" resultMap="${m.resBeaName}ResultMap">
		SELECT 
        <include refid="Base_Column_List" />
        FROM
        	${m.tableName} t
        WHERE t.del_flag='0'
			${m.listWhereStr}
	</select>
	
	<select id="selectByDto" resultMap="${m.resBeaName}ResultMap">
		SELECT 
        <include refid="Base_Column_List" />
        FROM
        	${m.tableName} t
        WHERE t.del_flag='0'
			${m.listWhereStr}
	</select>
	
	<select id="selectById" parameterType="${m.idType}" resultMap="${m.resBeaName}ResultMap">
		SELECT
         <include refid="Base_Column_List" />
        FROM
        	${m.tableName} t
        WHERE t.del_flag='0' and t.${m.idCol} = ${m.escape}{id}
	</select>
</mapper>